<?php
class keu_umk_detail_model extends MY_Model {
	var $model = 'keu_umk_detail';
	
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*							   
					FROM	KEU_UMK_DETAIL 
					WHERE	
							ID_UMK = '".post('id_umk')."'
					ORDER BY ".(post('sort')=='' ? 'NO_UMK' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('KEU_UMK_DETAIL', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('KEU_UMK_DETAIL', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_code){
		$result = $this->db->get_where('KEU_UMK_DETAIL', array('ID_UMK' => $as_code));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_code)
	{
		$ls_sql	= "	SELECT	d.*
					FROM	KEU_UMK_DETAIL d
					WHERE	d.ID_UMK = '".$as_code."'";
							
		$result	= $this->db->query($ls_sql);
		
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	
	function DeleteDetail($as_code)
	{
		try {
			$this->db->delete('KEU_UMK_DETAIL', array('ID_UMK' => $as_code));
			
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
	
	
	function DeleteDetailUMK($as_code, $an_no_umk)
	{
		try {
			$this->db->delete('KEU_UMK_DETAIL', array('ID_UMK' => $as_code, 'NO_UMK'=>$an_no_umk));
			
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
	
}
?>